package etnorservice.etnor_service.mapper.projectMapper;


import etnorservice.etnor_service.domain.DownloadRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DownloadRecordMapper {
    @Insert("INSERT INTO download_records(user_id, project_id, ip_address, download_date, is_successful) " +
            "VALUES(#{userId}, #{projectId}, #{ipAddress}, NOW(), #{isSuccessful})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insert(DownloadRecord record);

    @Select("SELECT * FROM download_records WHERE project_id = #{projectId} ORDER BY download_date DESC LIMIT #{offset}, #{limit}")
    List<DownloadRecord> findByProjectId(@Param("projectId") Long projectId, @Param("offset") int offset, @Param("limit") int limit);

    @Select("SELECT COUNT(*) FROM download_records WHERE project_id = #{projectId}")
    int countByProjectId(Long projectId);

    @Select("SELECT COUNT(*) FROM download_records WHERE user_id = #{userId}")
    int countByUserId(Long userId);
}
